package gui;

import java.text.ParseException;
import javax.swing.text.DefaultFormatter;
public class PermissionFormatter extends DefaultFormatter {
    
    public PermissionFormatter() {
        super();
    }
    
    // This method reads the text from model class to view class
    public String valueToString(Object permission) throws ParseException {
        return super.valueToString(permission);
    }
    
    // This method reads the text from view class to modal class and does the validations
    public Object stringToValue(String permission) throws ParseException {
        int offset = permission.indexOf(" ");
        if(offset != -1)
        {
            throw new ParseException("Permissions can't have a space in their name!", offset);
        }
        else
            return permission;
    }
}